package org.jground.rx.ui.zk.viewControl;

import org.jground.rx.RXView;
import org.jground.rx.ui.IMainFrame;
import org.jground.rx.ui.zk.UIFrame;
import org.jground.util.ArrayUtils;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.Checkbox;

public class UIAttributeControlBoolean extends UIAttributeControlBase {

    public UIAttributeControlBoolean createNew(UIFrame uiFrame, RXView moControl) {
        return new UIAttributeControlBoolean((UIFrame) uiFrame, moControl);
    }

    public UIAttributeControlBoolean() {}

    private Checkbox trueCb;

    private UIAttributeControlBoolean(IMainFrame<Component> uiFrame, RXView moControl) {
        super(uiFrame, moControl);
        add(trueCb = new Checkbox());
    }

    public void set(String... values) {
        clear();
        trueCb.setChecked(ArrayUtils.isNotEmpty(values) && values[0].equals("true"));
    }

    public String[] get() {
        return ArrayUtils.toArray(trueCb.isChecked() ? "true" : "false");
    }

    public void clear() {
        trueCb.setChecked(false);
    }

}
